package com.yiwei.hdb.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.hdb.R;
import com.yiwei.hdb.adapter.base.ItemAdapter;
import com.yiwei.hdb.model.V3HomeIndexModel;
import com.yiwei.hdb.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class OverDueBottomAdapter extends ItemAdapter<V3HomeIndexModel.DataBean.OverdueNotice, OverDueBottomAdapter.DefaultHolder> {

    private final int x20;
    private final int x360;
    private final int x420;



    private Context context;

    public OverDueBottomAdapter(Context context) {
        super(context);
        this.context = context;
        x20 = context.getResources().getDimensionPixelSize(R.dimen.x20);
        x360 = context.getResources().getDimensionPixelSize(R.dimen.x360);
        x420 = context.getResources().getDimensionPixelSize(R.dimen.x420);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_bottom_one_sec, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int poi) {

        V3HomeIndexModel.DataBean.OverdueNotice data = getItem(poi);
        if (poi == 0) {
            ViewGroup.LayoutParams lp = holder.layoutTotal.getLayoutParams();
            lp.width = x420;
            holder.layoutTotal.setLayoutParams(lp);
            holder.viewLeft.setVisibility(View.VISIBLE);
        } else {
            ViewGroup.LayoutParams lp = holder.layoutTotal.getLayoutParams();
            lp.width = x360;
            holder.layoutTotal.setLayoutParams(lp);
            holder.viewLeft.setVisibility(View.GONE);
        }


        Spanned info = Spans.with(context).font(data.real_name + "  " + data.sex, x20, 0xffffffff).
                font("  借款" + data.borrow_amount + "元\n逾期" + data.overdue_days + "天\n身份证:" + data.idno + "\n处理方式:" + data.handle, x20, 0x80ffffff).build();
        holder.txtContent.setText(info);


        if (poi % 3 == 0) {
            holder.layoutItem.setBackgroundResource(R.mipmap.img_overdue_one);
        } else if (poi % 3 == 1) {
            holder.layoutItem.setBackgroundResource(R.mipmap.img_overdue_two);
        } else if (poi % 3 == 2) {
            holder.layoutItem.setBackgroundResource(R.mipmap.img_overdue_three);
        }
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.view_left)
        View viewLeft;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.layout_item)
        LinearLayout layoutItem;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
